﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class DodadiVinarija : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Dodadi_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {


            string connectionString = ConfigurationManager.ConnectionStrings["gradovi"].ConnectionString;
            OleDbConnection connection = new OleDbConnection(connectionString);

            connection.Open();

            string imeGrad = gradV.SelectedItem.ToString();
            string select = "SELECT IdGrad FROM Gradovi where ImeGrad=?";
            OleDbCommand cmd1 = new OleDbCommand(select, connection);
            cmd1.Parameters.AddWithValue("?", imeGrad);
            int id = Convert.ToInt32(cmd1.ExecuteScalar());

            connection.Close();

            string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
            OleDbConnection conn = new OleDbConnection(conString);
            conn.Open();

            string insert = "insert into Vinarija (Ime, Adresa, email, telefon, grad, webstrana) values (?,?,?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(insert, conn);



            string ime = imeV.Text;
            string adresa = adresaV.Text;
            string email = emailV.Text;
            string telefon = telefonV.Text;
            //string grad = gradV.Text;
            string web = webV.Text;


            cmd.Parameters.AddWithValue("?", ime);
            cmd.Parameters.AddWithValue("?", adresa);
            cmd.Parameters.AddWithValue("?", email);
            cmd.Parameters.AddWithValue("?", telefon);
            cmd.Parameters.AddWithValue("?", id);
            cmd.Parameters.AddWithValue("?", web);
            cmd.ExecuteNonQuery();

            conn.Close();
            Response.Redirect("~/Administrator.aspx");

        }
    }
}
